﻿using System;
using System.Web;

namespace StubRssService
{
    public class ManagService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var op = (context.Request.QueryString["op"] ?? "").ToLower();
            switch (op)
            {
                case "clear":
                    Clear(context);
                    break;
                case "list":
                    List(context);
                    break;
                default:
                    UnknownCommand(op);
                    break;
            }
                
        }

        private static void UnknownCommand(string op)
        {
            throw new ApplicationException(string.Format("Command '{0}' unknown", op));
        }

        private static void Clear(HttpContext context)
        {
            Log.Clear();
            context.Response.ContentType = "text/plain";
            context.Response.Write("0");
        }

        private static void List(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(Log.LogDump);
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    }
}